import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class runFixed {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        for (int i=0;i<20;i++){
            Student stu = new Student("s"+i);
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    try{
                        int times = (int)(Math.random()*1000);
                        System.out.println("学生"+stu.getName()+ "开始考试，考场："+Thread.currentThread().getId());
                        if(times>500){
                            throw new Exception("考场"+Thread.currentThread().getId()+"中 学生"+stu.getName()+"时间为"+times+"毫秒，超过500毫秒，结束考试。");
                        }
                        Thread.sleep((int)(Math.random()*1000));
                        System.out.println(times+"毫秒后，学生"+stu.getName()+"结束考试...");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

        }
        pool.shutdown();
    }
}
